package cn.shadow.module.scene;

import com.google.common.collect.Maps;

import java.util.Map;

public class SelfThreadLocal<T> {

    private final Map<Thread, T> threadTMap = Maps.newConcurrentMap();
    private final IInit<T> init;

    public SelfThreadLocal(IInit<T> init) {
        this.init = init;
    }

    public T get() {
        Thread currentThread = Thread.currentThread();

        return this.threadTMap.computeIfAbsent(currentThread, k -> init.init());
    }

    public interface IInit<T> {
        T init();
    }

}
